import axios from 'axios';

const Myaxios = {}
Myaxios.install = function (Vue) {
  // 将自定义的 axios 实例对象挂载到 vue 插件
  const myAxiosObj = axios.create({
    baseURL: 'http://localhost:8888/api/private/v1',
  })

  // 添加请求拦截器
  myAxiosObj.interceptors.request.use(function (config) {
    // console.log(config);
    if (config.url !== '/login') {
      var token = JSON.parse(localStorage.getItem('userinfo')).token
      // console.log(token);
      config.headers.Authorization = token
    }
    return config;
  });

  Vue.prototype.$axios = myAxiosObj
}
export default Myaxios
